package containerio;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Mycount {
public static Map count(String []s){
	Map<String,Integer> m=new HashMap<String,Integer>();
	BufferedWriter bw;
	try {
		bw = new BufferedWriter(new FileWriter("D:\\code\\workspace\\highj\\src\\containerio\\output.txt"));
	
	for(int i=0;i<s.length;i++)
	{
		String mys=s[i];
		if(m.get(mys)==null)
			m.put(mys,1);
		else
			m.replace(mys,m.get(mys)+1);
	}
	int maxtimes;
	while(!m.isEmpty()) {
	maxtimes=0;
	Iterator<Integer> i=m.values().iterator();
	while(i.hasNext()) {
		int times=i.next();
		if(times>maxtimes)
			maxtimes=times;
	}
	Iterator<String> i1=m.keySet().iterator();
	while(i1.hasNext()) {
		String key=i1.next();
		int times=m.get(key);
		if(times==maxtimes)
		{
			bw.write(key+"   "+times+"\n");
			
			i1.remove();
		}
	}

	}
	bw.close();
	}
	catch (IOException e) {
		e.printStackTrace();
	}
	return m;
	
}
}
